package com.ty.zls.task;

import android.content.Context;
import android.graphics.Bitmap;

import com.ty.zls.bean.Constants;
import com.ty.zls.util.CommonUtil;
import com.ty.zls.util.HttpUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class WaterTask extends BaseTask {

    private Bitmap bitmap;

    public WaterTask(String url, Context context, SuccessCallback callback, Bitmap bitmap) {
        super(url, context, callback);
        this.bitmap = bitmap;
    }




    @Override
    protected Map<String, Object> doInBackground(Map<String, String>... maps) {
        Map<String, Object> data = new HashMap<>();
        try {
            JSONObject result = null;
            if(bitmap != null){
                result = HttpUtil.sendMuiltPartPost(context, CommonUtil.getFile(bitmap), HttpUtil.WATER_POST,maps[0]);

            }else{
                result = HttpUtil.sendNeedLoginPost(context, maps[0], HttpUtil.WATER_POST);
            }
            int code = result.optInt("code");
            data.put("code", code);
            data.put("msg", result.optString("msg"));
            data.put("result", result);
        } catch (Exception e) {
            data.put("code", Constants.ERROR_CODE);
        }
        return data;
    }

}
